package com.ubhave.powertrackernof1;

import java.util.Date;

import com.ubhave.powertrackernof1.R;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

//NOTE: REDUNDENT ACTIVITY NO LONGER USED. Keeping it for the time being incase we need to put it back in.

public class QuestionnaireMenuActivity extends Activity {
    
	SharedPreferences settings;
	int week;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.questionnairemenu);
        
        settings=PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        String[] startDateString = settings.getString("appStart", "").split("-");
		Date startDate = new Date(new Integer(startDateString[2]),new Integer(startDateString[1]),new Integer(startDateString[0]));
		Date currentDate = new Date();
		long diff = currentDate.getTime()-startDate.getTime();
		double daysDiff = diff/(1000*60*60*24);
		week=new Double(Math.ceil(daysDiff/7)).intValue()+1;
		
		
		if(settings.getBoolean("QDone-IMI"+week, false))
			findViewById(R.id.IMIButton).setBackgroundDrawable(getResources().getDrawable(R.drawable.btntick));
		if(settings.getBoolean("QDone-CSEActivity"+week, false))
			findViewById(R.id.CSEActivityButton).setBackgroundDrawable(getResources().getDrawable(R.drawable.btntick));
		if(settings.getBoolean("QDone-CSEEating"+week, false))
			findViewById(R.id.CSEEatingButton).setBackgroundDrawable(getResources().getDrawable(R.drawable.btntick));
		if(settings.getBoolean("QDone-ActionControl"+week, false))
			findViewById(R.id.ActionControlButton).setBackgroundDrawable(getResources().getDrawable(R.drawable.btntick));
		if(settings.getBoolean("QDone-TAM"+week, false)){
			Log.i("POWeR Tracker: ","bc "+findViewById(R.id.TAMButton));
			Log.i("POWeR Tracker: ","bc "+getResources().getDrawable(R.drawable.btntick));
			findViewById(R.id.TAMButton).setBackgroundDrawable(getResources().getDrawable(R.drawable.btntick));
		}
		if(settings.getBoolean("QDone-PIPS"+week, false))
			findViewById(R.id.PIPSButton).setBackgroundDrawable(getResources().getDrawable(R.drawable.btntick));
		if(settings.getBoolean("QDone-IPAQ"+week, false))
			findViewById(R.id.IPAQButton).setBackgroundDrawable(getResources().getDrawable(R.drawable.btntick));
		if(settings.getBoolean("QDone-FFQ"+week, false))
			findViewById(R.id.FFQButton).setBackgroundDrawable(getResources().getDrawable(R.drawable.btntick));
		
    }
    
    public void goQuestionnaireIMI(View v){
    	
    	if(settings.getBoolean("QDone-IMI"+week, false)==false){
    		Intent myIntent = new Intent(getBaseContext(), QuestionnaireActivity.class);
    		myIntent.putExtra("page", "1");
    		myIntent.putExtra("name", "IMI");
    		myIntent.putExtra("orientation", "H");
    		myIntent.putExtra("questionsPerPage", "5");
    		myIntent.putExtra("type", "Likert");
    		myIntent.putExtra("scale", "7");
    		myIntent.putExtra("labelMode", "0");
    		myIntent.putExtra("title", "IMI");
    		startActivity(myIntent);
    	}
    	else{
    		Toast.makeText(this, "You have already completed this questionnaire this week, please return next week.", Toast.LENGTH_SHORT).show();
    	}
    	
    }
    
    public void goQuestionnaireCSEActivity(View v){
    	
    	if(settings.getBoolean("QDone-CSEActivity"+week, false)==false){
    		Intent myIntent = new Intent(getBaseContext(), QuestionnaireActivity.class);
    		myIntent.putExtra("page", "1");
    		myIntent.putExtra("name", "CSEActivity");
    		myIntent.putExtra("orientation", "H");
    		myIntent.putExtra("questionsPerPage", "5");
    		myIntent.putExtra("type", "Likert");
    		myIntent.putExtra("scale", "4");
    		myIntent.putExtra("labelMode", "0");
    		myIntent.putExtra("title", "Coping SE Activity");
    		startActivity(myIntent);
    	}
    	else{
    		Toast.makeText(this, "You have already completed this questionnaire this week, please return next week.", Toast.LENGTH_SHORT).show();
    	}
    }
    
    public void goQuestionnaireCSEEating(View v){
    	
    	if(settings.getBoolean("QDone-CSEEating"+week, false)==false){
    		Intent myIntent = new Intent(getBaseContext(), QuestionnaireActivity.class);
    		myIntent.putExtra("page", "1");
    		myIntent.putExtra("name", "CSEEating");
    		myIntent.putExtra("orientation", "H");
    		myIntent.putExtra("questionsPerPage", "5");
    		myIntent.putExtra("type", "Likert");
    		myIntent.putExtra("scale", "4");
    		myIntent.putExtra("labelMode", "0");
    		myIntent.putExtra("title", "Coping SE Eating");
    		startActivity(myIntent);
    	}
    	else{
    		Toast.makeText(this, "You have already completed this questionnaire this week, please return next week.", Toast.LENGTH_SHORT).show();
    	}
    }
    
    public void goQuestionnaireActionControl(View v){
    	
    	if(settings.getBoolean("QDone-ActionControl"+week, false)==false){
    		Intent myIntent = new Intent(getBaseContext(), QuestionnaireActivity.class);
    		myIntent.putExtra("page", "1");
    		myIntent.putExtra("name", "ActionControl");
    		myIntent.putExtra("orientation", "H");
    		myIntent.putExtra("questionsPerPage", "5");
    		myIntent.putExtra("type", "Likert");
    		myIntent.putExtra("scale", "4");
    		myIntent.putExtra("labelMode", "0");
    		myIntent.putExtra("title", "Action Control");
    		startActivity(myIntent);
    	}
    	else{
    		Toast.makeText(this, "You have already completed this questionnaire this week, please return next week.", Toast.LENGTH_SHORT).show();
    	}
    }
    
    public void goQuestionnaireTAM(View v){
    	
    	if(settings.getBoolean("QDone-TAM"+week, false)==false){
    		Intent myIntent = new Intent(getBaseContext(), QuestionnaireActivity.class);
    		myIntent.putExtra("page", "1");
    		myIntent.putExtra("name", "TAM");
    		myIntent.putExtra("orientation", "V");
    		myIntent.putExtra("questionsPerPage", "1");
    		myIntent.putExtra("type", "Likert");
    		myIntent.putExtra("scale", "7");
    		myIntent.putExtra("labelMode", "1");
    		myIntent.putExtra("title", "TAM");
    		startActivity(myIntent);
    	}
    	else{
    		Toast.makeText(this, "You have already completed this questionnaire this week, please return next week.", Toast.LENGTH_SHORT).show();
    	}
    }
    
    public void goQuestionnairePIPS(View v){
    	
    	if(settings.getBoolean("QDone-PIPS"+week, false)==false){
    		Intent myIntent = new Intent(getBaseContext(), QuestionnaireActivity.class);
    		myIntent.putExtra("page", "1");
    		myIntent.putExtra("name", "PIPS");
    		myIntent.putExtra("orientation", "V");
    		myIntent.putExtra("questionsPerPage", "1");
    		myIntent.putExtra("type", "Likert");
    		myIntent.putExtra("scale", "10");
    		myIntent.putExtra("labelMode", "1");
    		myIntent.putExtra("title", "PIPS");
    		startActivity(myIntent);
    	}
    	else{
    		Toast.makeText(this, "You have already completed this questionnaire this week, please return next week.", Toast.LENGTH_SHORT).show();
    	}
    }
    
    public void goQuestionnaireIPAQ(View v){
    	
    	if(settings.getBoolean("QDone-IPAQ"+week, false)==false){
    		/*Intent myIntent = new Intent(getBaseContext(), QuestionnaireActivity.class);
    		myIntent.putExtra("page", "1");
    		startActivity(myIntent);*/
    		Toast.makeText(this, "Questionnaire not yet available.", Toast.LENGTH_SHORT).show();
        	
    	}
    	else{
    		Toast.makeText(this, "You have already completed this questionnaire this week, please return next week.", Toast.LENGTH_SHORT).show();
    	}
    }
    
    public void goQuestionnaireFFQ(View v){
    	
    	if(settings.getBoolean("QDone-FFQ"+week, false)==false){
    		/*Intent myIntent = new Intent(getBaseContext(), QuestionnaireActivity.class);
    		myIntent.putExtra("page", "1");
    		startActivity(myIntent);*/
    		Toast.makeText(this, "Questionnaire not yet available.", Toast.LENGTH_SHORT).show();
    	}
    	else{
    		Toast.makeText(this, "You have already completed this questionnaire this week, please return next week.", Toast.LENGTH_SHORT).show();
    	}
    }
    
    
    public void goQuestionnaireDMP(View v){
    	   	
    		Intent myIntent = new Intent(getBaseContext(), QuestionnaireActivity.class);
    		myIntent.putExtra("page", "1");
    		myIntent.putExtra("name", "GoalEffort");
    		myIntent.putExtra("orientation", "H");
    		myIntent.putExtra("questionsPerPage", "3");
    		myIntent.putExtra("type", "Likert");
    		myIntent.putExtra("scale", "7");
    		myIntent.putExtra("labelMode", "0");
    		myIntent.putExtra("title", " ");
    		myIntent.putExtra("multipart", "0");
    		startActivity(myIntent);
    	
    }
    
}